package com.shop.cereshop.business.storage;

import com.shop.cereshop.business.alioss.service.TencentFileUploadService;
import com.shop.cereshop.commons.upload.strategy.FileStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;

@Configuration
@Slf4j
@ConditionalOnProperty(name = "upload.type", havingValue = "TENCENT")
public class TencentCosAutoConfigure {

    @Service
    public class TencentCosServiceImpl implements FileStrategy {

        @Autowired
        private TencentFileUploadService fileUploadService;

        @Override
        public String upload(MultipartFile file) throws Exception {
            return fileUploadService.uploadFile(file.getOriginalFilename(), file.getInputStream(), file.getSize());
        }

        @Override
        public String uploadStream(String fileName, byte[] bytes, InputStream inputStream, long size) throws Exception {
            return fileUploadService.uploadFile(fileName, inputStream, size);
        }

        @Override
        public InputStream getInputStream(String url) {
            return null;
        }
    }
}
